package com.java.comprehensive.arithmetic.leecode.easy;

/**
 * @program: comprehensive-service
 *
 * @description: 回文数
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-23 13:54
 **/
public class LeetCode_09 {

	public boolean isPalindrome(int x) {
		boolean flag = false;
		StringBuilder stringBuilder = new StringBuilder(String.valueOf(x));
		String string = stringBuilder.reverse().toString();
		flag = string.equals(String.valueOf(x));
		return flag;
	}

	public boolean isPalindrome_1(int x) {
		if (x < 0)
			return false;
		int result = 0;
		int temp = x;
		while (temp != 0) {
			int b = temp % 10;
			result = result * 10 + b;
			temp = temp / 10;
		}
		return result == x;
	}
	static class Solution {
		public boolean isPalindrome(int x) {
			int b;
			long a = 0;
			int  temp = x;
			while (temp != 0) {
				b = temp % 10;
				if (b < 0) {
					return false;
				}
				a = a * 10 + b;
				temp = temp / 10;
			}
			return (int) a == x;
		}
	}
	public static void main(String[] args) {
		int x = 121;
		LeetCode_09 leetCode_09 = new LeetCode_09();
		System.out.println(leetCode_09.isPalindrome_1(x));
	}

}
